package com.jhc.common.core.enums;

import com.jhc.common.core.utils.Null;
import com.jhc.common.core.web.page.PageFilter;

public enum FilterType {
    EQ,LIKE,GE,LE,BETWEEN;

    public static void handle(StringBuilder sql, PageFilter filter){
        if (Null.allNotEmpty(filter.getColumn(),filter.getType(),filter.getType())){
            sql.append(" and ").append(filter.getColumn());
            switch (filter.getType()){
                case LIKE:
                    sql.append(" like '%")
                        .append(filter.getValue())
                        .append("%");
                    break;
                case GE:
                    sql.append(">='")
                        .append(filter.getValue());
                    break;
                case LE:
                    sql.append("<='")
                            .append(filter.getValue());
                    break;
                case EQ:
                    sql.append("='")
                        .append(filter.getValue());
                    break;
                case BETWEEN:
                    String[] split = filter.getValue().split(",");
                    sql.append(" between '")
                        .append(split[0])
                        .append("' and '")
                        .append(split[1]);
                    break;
            }
            sql.append("'");
        }

    }

}
